/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.hibernate.core;

import com.blandware.atleap.model.core.GlobalProperty;
import com.blandware.atleap.persistence.core.GlobalPropertyDAO;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>This class interacts with Spring's HibernateTemplate to save/delete and
 * retrieve GlobalProperty objects.
 * </p>
 * <p><a href="GlobalPropertyDAOHibernate.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 */
public class GlobalPropertyDAOHibernate extends BaseDAOHibernate implements GlobalPropertyDAO {

	/**
	 * @see com.blandware.atleap.persistence.core.GlobalPropertyDAO#createGlobalProperty(com.blandware.atleap.model.core.GlobalProperty)
	 */
	public void createGlobalProperty(GlobalProperty globalProperty) {
		getHibernateTemplate().save(globalProperty);
	}

	/**
	 * @see com.blandware.atleap.persistence.core.GlobalPropertyDAO#retrieveGlobalProperty(String)
	 */
	public GlobalProperty retrieveGlobalProperty(String propertyName) {
		return (GlobalProperty) getHibernateTemplate().get(GlobalProperty.class, propertyName);
	}

	/**
	 * @see com.blandware.atleap.persistence.core.GlobalPropertyDAO#updateGlobalProperty(com.blandware.atleap.model.core.GlobalProperty)
	 */
	public void updateGlobalProperty(GlobalProperty globalProperty) {
		getHibernateTemplate().update(globalProperty);
	}

	/**
	 * @see com.blandware.atleap.persistence.core.GlobalPropertyDAO#deleteGlobalProperty(com.blandware.atleap.model.core.GlobalProperty)
	 */
	public void deleteGlobalProperty(GlobalProperty globalProperty) {
		getHibernateTemplate().delete(globalProperty);
	}

	/**
	 * @see com.blandware.atleap.persistence.core.GlobalPropertyDAO#listDynamicProperties()
	 */
	public List listDynamicProperties() {
		String hql = "select p from GlobalProperty p order by p.name";
		List list = executeFind(hql);
		if ( list == null ) {
			list = new ArrayList();
		}
		return list;
	}

}

